package com.huawei.appmarket.service.store.awk.card;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.store.bean.detail.DetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.Space;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.framework.widget.RoundCornerLayout;
import com.huawei.appmarket.service.store.awk.bean.HorizonalHomeCardItemBean;
import com.huawei.appmarket.service.store.awk.bean.HorizontalYouMayLikeCardBean;
import huawei.widget.HwProgressBar;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import o.AccountBussinessListener;
import o.ccp;
import o.ccz;
import o.cfw;
import o.cgz;
import o.chc;
import o.chy;
import o.chz;
import o.clm;
import o.clp;
import o.cvt;
import o.BaseRequest;
import o.dgh;
import o.dgm;
import o.dky.c;
import o.dof;
import o.dyk;
import o.eib;
import o.eoj;
import o.epw;
import o.CollectCheck;
import o.ewm.d;
import o.ewm.e;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class HorizontalYouMayLikeAppCard extends BaseDistCard {
    private static int ʼ = 3;
    private TextView ʻ;
    private ArrayList<View> ʻॱ;
    private View ʽ;
    private ImageView ˊॱ;
    protected clp ˋ;
    private Animation ˋॱ;
    private dyk ˋᐝ;
    private int ˍ;
    private Handler ˎˎ = new Handler();
    private TextView ˏॱ;
    private HwProgressBar ͺ;
    private View ॱˊ;
    private chz ॱˋ;
    private ArrayList<ThreeLineAppSingleItemCard> ॱˎ;
    private String ॱॱ = ("HorizontalYouMayLikeAppCard" + System.currentTimeMillis());
    private int ॱᐝ = -1;
    private ImageView ᐝ;
    private int ᐝॱ;

    class a implements IServerCallBack {
        final /* synthetic */ HorizontalYouMayLikeAppCard ˎ;

        a(HorizontalYouMayLikeAppCard horizontalYouMayLikeAppCard) {
            this.ˎ = horizontalYouMayLikeAppCard;
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            boolean z = false;
            if ((responseBean instanceof DetailResponse) && responseBean.getResponseCode() == 0) {
                DetailResponse detailResponse = (DetailResponse) responseBean;
                if (detailResponse.getRtnCode_() == 0) {
                    this.ˎ.ˋ.ˏ(detailResponse);
                    if (this.ˎ.ˊᐝ instanceof HorizontalYouMayLikeCardBean) {
                        HorizontalYouMayLikeCardBean horizontalYouMayLikeCardBean = (HorizontalYouMayLikeCardBean) this.ˎ.ˊᐝ;
                        int ʽ = this.ˎ.ʼ() * HorizontalYouMayLikeAppCard.ʼ;
                        if (horizontalYouMayLikeCardBean.ʻˋ().size() < this.ˎ.ॱᐝ + ʽ) {
                            this.ˎ.ॱᐝ = horizontalYouMayLikeCardBean.ʻˋ().size();
                        } else {
                            this.ˎ.ॱᐝ = ʽ + this.ˎ.ॱᐝ;
                        }
                        horizontalYouMayLikeCardBean.ʻˋ().clear();
                        horizontalYouMayLikeCardBean.ʻˋ().addAll(this.ˎ.ˋ.ॱ());
                        horizontalYouMayLikeCardBean.ॱ(this.ˎ.ˋ.ॱॱ());
                        horizontalYouMayLikeCardBean.ॱˊ(this.ˎ.ˋ.ˊ());
                        horizontalYouMayLikeCardBean.ᐝ(this.ˎ.ॱᐝ);
                        this.ˎ.ˏ(this.ˎ.ˊᐝ);
                        z = true;
                    } else {
                        return;
                    }
                }
            }
            this.ˎ.ˋ(z);
        }
    }

    class b implements AccountBussinessListener {
        final /* synthetic */ HorizontalYouMayLikeAppCard ˊ;

        private b(HorizontalYouMayLikeAppCard horizontalYouMayLikeAppCard) {
            this.ˊ = horizontalYouMayLikeAppCard;
        }

        public void onAccountBusinessResult(ccp o_ccp) {
            if (102 == o_ccp.ˎ || 103 == o_ccp.ˎ) {
                this.ˊ.ˎˎ.post(new Runnable(this) {
                    final /* synthetic */ b ॱ;

                    {
                        this.ॱ = r1;
                    }

                    public void run() {
                        this.ॱ.ˊ.ͺ();
                    }
                });
            }
        }
    }

    public HorizontalYouMayLikeAppCard(Context context) {
        super(context);
    }

    public View ˎ() {
        return this.ʽ;
    }

    public cgz ˏ(View view) {
        this.ᐝॱ = ˊ(this.ʼॱ) + this.ʼॱ.getResources().getDimensionPixelSize(d.ॱˊ);
        this.ˍ = (ˊ(this.ʼॱ) + this.ʼॱ.getResources().getDimensionPixelSize(d.ˏॱ)) + this.ʼॱ.getResources().getDimensionPixelSize(d.ߵ);
        this.ʽ = view.findViewById(j.ʼꞌ);
        ॱ((TextView) view.findViewById(j.ʼﾞ));
        this.ᐝ = (ImageView) view.findViewById(j.ॱˑ);
        Drawable drawable = this.ʼॱ.getDrawable(e.ˊ);
        drawable.setAlpha(epw.ˏ() ? 51 : 255);
        this.ᐝ.setImageDrawable(drawable);
        this.ʻ = (TextView) view.findViewById(j.ˈᶥ);
        eoj.ˋ().ˎ(this.ॱॱ, new b());
        ͺ();
        this.ॱˊ = view.findViewById(j.ꞌʽ);
        this.ॱˊ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ HorizontalYouMayLikeAppCard ॱ;

            {
                this.ॱ = r1;
            }

            public void onClick(View view) {
                this.ॱ.ॱ(this.ॱ.ʼॱ, this.ॱ.ˊᐝ);
                this.ॱ.ᐝ();
            }
        });
        this.ˊॱ = (ImageView) view.findViewById(j.ﹳʻ);
        this.ͺ = (HwProgressBar) view.findViewById(j.ﹳͺ);
        this.ˏॱ = (TextView) view.findViewById(j.ﹶˊ);
        this.ˋॱ = new RotateAnimation(0.0f, 180.0f, 1, 0.5f, 1, 0.5f);
        this.ˋॱ.setDuration(300);
        ((RoundCornerLayout) view.findViewById(j.ﾞॱ)).setPadding(eib.ॱॱ(), 0, eib.ʽ(), 0);
        LinearLayout linearLayout = (LinearLayout) view.findViewById(j.ﾟॱ);
        int ʼ = ʼ();
        int dimensionPixelSize = this.ʼॱ.getResources().getDimensionPixelSize(d.ˋʻ);
        LayoutInflater from = LayoutInflater.from(this.ʼॱ);
        this.ॱˎ = new ArrayList();
        this.ʻॱ = new ArrayList();
        LayoutParams layoutParams = new LinearLayout.LayoutParams(dimensionPixelSize, -1);
        for (int i = 0; i < ʼ; i++) {
            View linearLayout2 = new LinearLayout(this.ʼॱ);
            LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-2, -2);
            layoutParams2.weight = 1.0f;
            linearLayout2.setLayoutParams(layoutParams2);
            linearLayout2.setOrientation(1);
            for (dimensionPixelSize = 0; dimensionPixelSize < ʼ; dimensionPixelSize++) {
                View inflate = from.inflate(h.ᐝㆍ, null);
                ThreeLineAppSingleItemCard threeLineAppSingleItemCard = new ThreeLineAppSingleItemCard(this.ʼॱ);
                threeLineAppSingleItemCard.ˏ(inflate);
                this.ॱˎ.add(threeLineAppSingleItemCard);
                linearLayout2.addView(inflate);
                inflate = from.inflate(h.ᐧˋ, null);
                this.ʻॱ.add(inflate.findViewById(j.ʾॱ));
                linearLayout2.addView(inflate);
            }
            if (i > 0) {
                linearLayout.addView(new Space(this.ʼॱ), layoutParams);
            }
            linearLayout.addView(linearLayout2, layoutParams2);
        }
        ʽ(view);
        if (this.ˋ == null) {
            this.ˋ = new clp();
        }
        return this;
    }

    private void ॱ(CardBean cardBean, View view) {
        if (cardBean instanceof HorizonalHomeCardItemBean) {
            int i;
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            if (dof.ʽ(((HorizonalHomeCardItemBean) cardBean).ʽॱ())) {
                i = this.ᐝॱ;
            } else {
                i = this.ˍ;
            }
            layoutParams.setMarginStart(i);
            view.setLayoutParams(layoutParams);
            view.setVisibility(0);
        }
    }

    protected int ˊ(Context context) {
        return this.ʼॱ.getResources().getDimensionPixelSize(c.ˎ);
    }

    private int ʼ() {
        return chc.ॱᐝ();
    }

    private boolean ˏ(Context context, CardBean cardBean) {
        if (!(cardBean instanceof HorizontalYouMayLikeCardBean)) {
            return false;
        }
        HorizontalYouMayLikeCardBean horizontalYouMayLikeCardBean = (HorizontalYouMayLikeCardBean) cardBean;
        if (CollectCheck.isEmpty(horizontalYouMayLikeCardBean.ʻˋ())) {
            return false;
        }
        if (horizontalYouMayLikeCardBean.ʻˋ().size() > horizontalYouMayLikeCardBean.ʼˊ() || horizontalYouMayLikeCardBean.ʾॱ() != 0) {
            return true;
        }
        return false;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (dof.ʽ(cardBean.ॱॱ()) || !ˏ(this.ʿ.getContext(), cardBean)) {
            ˎ().setVisibility(8);
        } else {
            ˎ().setVisibility(0);
        }
        if (cardBean instanceof HorizontalYouMayLikeCardBean) {
            HorizontalYouMayLikeCardBean horizontalYouMayLikeCardBean = (HorizontalYouMayLikeCardBean) cardBean;
            if (horizontalYouMayLikeCardBean.ʽˊ()) {
                ˋॱ();
            }
            ॱ(horizontalYouMayLikeCardBean);
            if (this.ॱᐝ == -1) {
                this.ॱᐝ = horizontalYouMayLikeCardBean.ﾟ();
            }
            int ʼ = ʼ();
            for (int i = 0; i < ʼ * ʼ; i++) {
                ThreeLineAppSingleItemCard threeLineAppSingleItemCard = (ThreeLineAppSingleItemCard) this.ॱˎ.get(i);
                View view = (View) this.ʻॱ.get(i);
                int i2 = this.ॱᐝ + i;
                if (i2 < horizontalYouMayLikeCardBean.ʻˋ().size()) {
                    CardBean cardBean2 = (HorizonalHomeCardItemBean) horizontalYouMayLikeCardBean.ʻˋ().get(i2);
                    threeLineAppSingleItemCard.ˏ(cardBean2);
                    threeLineAppSingleItemCard.ˉ().setVisibility(0);
                    if ((i + 1) % ʼ == 0) {
                        view.setVisibility(4);
                    } else {
                        view.setVisibility(0);
                        ॱ(cardBean2, view);
                    }
                    ˊ((BaseCardBean) cardBean2);
                } else {
                    threeLineAppSingleItemCard.ˉ().setVisibility(4);
                    view.setVisibility(4);
                }
            }
        }
    }

    public void ॱ(chz o_chz) {
        this.ॱˋ = o_chz;
    }

    public void ॱ(chy o_chy) {
        for (int i = 0; i < this.ॱˎ.size(); i++) {
            ((ThreeLineAppSingleItemCard) this.ॱˎ.get(i)).ॱ(o_chy);
        }
    }

    private void ᐝ() {
        if (this.ˊᐝ instanceof HorizontalYouMayLikeCardBean) {
            HorizontalYouMayLikeCardBean horizontalYouMayLikeCardBean = (HorizontalYouMayLikeCardBean) this.ˊᐝ;
            if (!horizontalYouMayLikeCardBean.ʽˊ()) {
                int ʼ = ʼ() * ʼ;
                int i = this.ॱᐝ + ʼ;
                int size = horizontalYouMayLikeCardBean.ʻˋ().size();
                if (size >= i + ʼ) {
                    ʻ();
                    this.ॱᐝ = i;
                    horizontalYouMayLikeCardBean.ᐝ(i);
                    ˏ(this.ˊᐝ);
                } else if (size <= i || size >= ʼ + i) {
                    if (this.ˋ.ॱॱ()) {
                        ˏॱ();
                        return;
                    }
                    ʻ();
                    this.ॱᐝ = 0;
                    horizontalYouMayLikeCardBean.ᐝ(0);
                    ˏ(this.ˊᐝ);
                } else if (this.ˋ.ॱॱ()) {
                    ˏॱ();
                } else {
                    ʻ();
                    this.ॱᐝ = i;
                    horizontalYouMayLikeCardBean.ᐝ(i);
                    ˏ(this.ˊᐝ);
                }
            }
        }
    }

    private void ʻ() {
        this.ˊॱ.startAnimation(this.ˋॱ);
    }

    private void ˋॱ() {
        if (this.ˊᐝ instanceof HorizontalYouMayLikeCardBean) {
            ((HorizontalYouMayLikeCardBean) this.ˊᐝ).ˏ(true);
            this.ͺ.setVisibility(0);
            this.ˊॱ.setVisibility(8);
            this.ˏॱ.setText(this.ʼॱ.getResources().getString(n.ˊߴ));
            this.ॱˊ.setContentDescription(this.ʼॱ.getResources().getString(n.ˊߴ));
        }
    }

    private void ˋ(boolean z) {
        if (this.ˊᐝ instanceof HorizontalYouMayLikeCardBean) {
            ((HorizontalYouMayLikeCardBean) this.ˊᐝ).ˏ(false);
            this.ͺ.setVisibility(8);
            if (z) {
                this.ˊॱ.setVisibility(0);
                this.ˏॱ.setText(this.ʼॱ.getResources().getString(n.ߵᐝ));
                this.ॱˊ.setContentDescription(this.ʼॱ.getResources().getString(n.ߵᐝ));
                return;
            }
            this.ˊॱ.setVisibility(8);
            this.ˏॱ.setText(this.ʼॱ.getResources().getString(n.ˊꜞ));
            this.ॱˊ.setContentDescription(this.ʼॱ.getResources().getString(n.ˊꜞ));
        }
    }

    public ArrayList<String> ˋ() {
        ArrayList<String> arrayList = new ArrayList();
        if (this.ˊᐝ instanceof HorizontalYouMayLikeCardBean) {
            List ʻˋ = ((HorizontalYouMayLikeCardBean) this.ˊᐝ).ʻˋ();
            if (ʻˋ != null) {
                int ʼ = ʼ();
                for (int i = 0; i < ʼ * ʼ; i++) {
                    int i2 = this.ॱᐝ + i;
                    if (i2 < ʻˋ.size()) {
                        HorizonalHomeCardItemBean horizonalHomeCardItemBean = (HorizonalHomeCardItemBean) ʻˋ.get(i2);
                        arrayList.add(horizonalHomeCardItemBean.ॱॱ() + "#$#" + horizonalHomeCardItemBean.u_());
                    }
                }
            }
        }
        return arrayList;
    }

    private void ˊ(BaseCardBean baseCardBean) {
        int ॱ = ccz.ॱ();
        if (this.ʼॱ != null) {
            ॱ = dgm.ˎ((Activity) this.ʼॱ);
        }
        if (this.ˋᐝ == null) {
            this.ˋᐝ = new dyk(ॱ);
        }
        this.ˋᐝ.ॱ(baseCardBean);
    }

    private void ˏॱ() {
        if (this.ॱˋ != null) {
            ˋॱ();
            HorizontalYouMayLikeCardBean horizontalYouMayLikeCardBean = (HorizontalYouMayLikeCardBean) this.ˊᐝ;
            cvt o_clm = new clm();
            o_clm.ˎ(this.ॱˋ.ʽ());
            o_clm.ˋ(this.ˋ.ˊ());
            o_clm.ॱ(horizontalYouMayLikeCardBean.ॱˉ());
            o_clm.ˊ(horizontalYouMayLikeCardBean.u_());
            o_clm.ˏ(horizontalYouMayLikeCardBean.ʻˊ());
            int ॱ = ccz.ॱ();
            if (this.ʼॱ != null) {
                ॱ = dgm.ˎ((Activity) this.ʼॱ);
            }
            o_clm.setServiceType_(ॱ);
            cfw.ˎ(o_clm, new a(this));
        }
    }

    private void ॱ(HorizontalYouMayLikeCardBean horizontalYouMayLikeCardBean) {
        this.ˋ.ॱ(horizontalYouMayLikeCardBean.ʽᐝ());
        this.ˋ.ॱ(horizontalYouMayLikeCardBean.ʽˋ());
        this.ˋ.ˏ(horizontalYouMayLikeCardBean.u_());
        if (CollectCheck.isEmpty(horizontalYouMayLikeCardBean.ʻˋ()) || horizontalYouMayLikeCardBean.ʻˋ().size() < horizontalYouMayLikeCardBean.ʼˊ() || horizontalYouMayLikeCardBean.ʾॱ() == 0) {
            this.ˋ.ॱ(false);
        }
        this.ˋ.ॱ().clear();
        if (!CollectCheck.isEmpty(horizontalYouMayLikeCardBean.ʻˋ())) {
            for (HorizonalHomeCardItemBean ˋˋ : horizontalYouMayLikeCardBean.ʻˋ()) {
                ˋˋ.ˋˋ(horizontalYouMayLikeCardBean.ॱˉ());
            }
            this.ˋ.ॱ().addAll(horizontalYouMayLikeCardBean.ʻˋ());
        }
    }

    private void ͺ() {
        if (UserSession.getInstance().isLoginSuccessful()) {
            String userName = UserSession.getInstance().getUserName();
            this.ʻ.setText(this.ʼॱ.getResources().getString(n.ۥॱ, new Object[]{userName}));
        } else {
            this.ʻ.setText(this.ʼॱ.getResources().getString(n.ߵˊ));
        }
        this.ʻ.requestLayout();
    }

    public void ˊ() {
        eoj.ˋ().ˊ(this.ॱॱ);
    }

    private void ॱ(Context context, CardBean cardBean) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("detailID", cardBean.ॱॱ());
        dgh.ˋ("370201", linkedHashMap);
    }
}
